/* See LICENSE.dwm file for copyright and license details. */
#include <stdbool.h>

extern const bool openlog;

void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size);

#define MIN(A, B)               ((A) < (B) ? (A) : (B))

FILE *getlogfd(void);
void loginit(void);
void get_time_str(char *, int);
void flushlog(void);

#define LOG_INFO_FLUSH(fmt, ...) do { \
    LOG_INFO(fmt, ##__VA_ARGS__); \
    flushlog(); \
}while(0)

// #fmt 会拼接成 带双引号的 "fmt"
#define LOG_INFO(fmt, ...) if(openlog) { \
    char timee[TIME_STR_LEN]; \
    get_time_str(timee, TIME_STR_LEN); \
    fprintf(getlogfd(), "[%s I] "fmt" ",  timee, __VA_ARGS__); \
}

#define TIME_STR_LEN 20